<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('商品列表')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>商品名称：</label>
                                <input type="text" name="name"/>
                            </li>
                            <li>
                                <label>商品类别：</label>
                                <select id="typeId" name="typeId" class="form-control m-b">
                                    <option value="">所有</option>
                                <option th:each="dict : ${typeList}" th:text="${dict.name}"
                                        th:value="${dict.id}" ></option>
                                </select>
                            </li>
                            <li>
                                <label>商品分类：</label>
                                <select name="classId" class="form-control m-b"  >
                                    <option value="">所有</option>
                                    <option th:each="dict : ${classList}" th:text="${dict.allName}" th:value="${dict.id}"></option>
                                </select>
                            </li>
                            <li>
                                <label>专区：</label>
                                <select name="status" th:with="type=${@dict.getType('goods_status')}" class="form-control m-b" >
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:goods:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:goods:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:goods:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <!--<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:goods:export">-->
                    <!--<i class="fa fa-download"></i> 导出-->
                <!--</a>-->
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:goods:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:goods:remove')}]];
        var hasSpecDatas = [[${@dict.getType('goods_has_spec')}]];
        var hasSpikeDatas = [[${@dict.getType('goods_has_spike')}]];
        var isBrandDatas = [[${@dict.getType('goods_is_brand')}]];
        var isAbroadDatas = [[${@dict.getType('goods_is_abroad')}]];
        var isRecommendDatas = [[${@dict.getType('goods_is_recommend')}]];
        var isHotDatas = [[${@dict.getType('goods_is_hot')}]];
        var isPointDiscountDatas = [[${@dict.getType('goods_is_point_discount')}]];
        var statusDatas = [[${@dict.getType('goods_status')}]];
        var tagDatas = [[${@dict.getType('goods_tag')}]];
        var prefix = ctx + "system/goods";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "商品",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id', 
                    title: 'ID',
                    visible: false
                },
                {
                    field: 'name', 
                    title: '商品名称',
                    width: 250
                },
                // {
                //     field: 'className',
                //     title: '商品分类'
                // },
                {
                    field: 'typeName',
                    title: '商品类型'
                },
                // {
                //     field: 'tag',
                //     title: '标签',
                //     formatter: function(value, row, index) {
                //         return $.table.selectDictLabel(tagDatas, value);
                //     }
                // },
                // {
                //     field: 'brandName',
                //     title: '商品品牌'
                // },
                {
                    field: 'mainUrl', 
                    title: '主图',
                    formatter: function(value, row, index) {
                        if(value!=null&&value!=''){
                            return '<img src="'+value+'" style="width:80px;" >';
                        }
                        return '';
                    }
                },
                    {
                        field: 'sort',
                        title: '排序'
                    },
                {
                    field: 'postFee', 
                    title: '默认邮费'
                },
                {
                    field: 'monthlySales', 
                    title: '月售'
                },
                {
                    field: 'stock', 
                    title: '库存'
                },
                {
                    field: 'status', 
                    title: '专区',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                    {
                        field: 'category',
                        title: '下架前所属专区',
                        formatter: function(value, row, index) {
                            if (value==0){
                                return '<span class="label label-success">每日爆品</span>';
                            }
                            if (value==1){
                                return '<span class="label label-success">秒杀专区</span>';
                            }
                            if (value==2){
                                return '<span class="label label-success">好物推荐</span>';
                            }
                            if (value==3){
                                return '<span class="label label-success">新人专享</span>';
                            }
                            if (value==4){
                                return '<span class="label label-success">积分专区</span>';
                            }
                            return value ;
                        }
                    },
                    {
                        field: 'applyNum',
                        title: '开团申请',
                        sortable: true
                    },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var e = '<a class="btn btn-primary btn-sm '+editFlag+'" href="#" mce_href="#" title="编辑" onclick="$.operate.editShadeClose(\''
                            + row.id
                            + '\',false)"><i class="fa fa-edit"></i></a> ';
                        var d = '<a class="btn btn-warning btn-sm '+removeFlag+'" href="#" title="删除"  mce_href="#" onclick="$.operate.remove(\''
                            + row.id
                            + '\')"><i class="fa fa-remove"></i></a> ';
                        var f = '<a class="btn btn-success btn-sm" href="#" title="上下架"  mce_href="#" onclick="resetShelf(\''
                            + row.id
                            + '\')"><i class="fa fa-key"></i></a> ';
                        var m = '<a class="btn btn-success btn-sm' +editFlag+ '" href="#" title="运费"  mce_href="#" onclick="goPostFee(\''
                            + row.id
                            + '\')"><i class="fa fa-truck"></i></a> ';
                        var k = '<a class="btn btn-success btn-sm" href="#" title="区域设置"  mce_href="#" onclick="region(\''
                            + row.id
                            + '\')"><i class="fa fa-tag"></i></a> ';
                        return e + d +m + k;
                    }
                }]
            };
            $.table.init(options);
        });
        //设置地区运费
        function goPostFee(id) {
            // layer.open({
            //     type : 2,
            //     title : '增加',
            //     maxmin : true,
            //     shadeClose : false, // 点击遮罩关闭层
            //     area : [ '800px', '520px' ],
            //     content : prefix + '/goPostFee/' + id // iframe的url
            // });
            $.modal.open("设置地区运费" ,  prefix + "/goPostFee/"+id);
        }

        //设置区域
        function region(id) {
            // layer.open({
            //     type : 2,
            //     title : '区域设置',
            //     maxmin : true,
            //     shadeClose : false, // 点击遮罩关闭层
            //     area : [ '800px', '520px' ],
            //     content : prefix + '/region/'+id // iframe的url
            // });
            $.modal.open("设置禁止发货区域" ,  prefix + "/region/"+id);
        }
    </script>
</body>
</html>